package com.sport.common.web.model;


import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable{
    private static final long serialVersionUID = 1L;

    /**
     *  响应码
     */
    private int code;
    /**
     *  响应信息
     */
    private String msg;
    /**
     *  响应结果
     */
    private T data;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public Result(T data) {
        this.data = data;
    }

    /**
     *  消息发送成功
     * @return  返回响应消息
     */
    public static <T> Result<T> success() {
        return new Result<T>(200, "成功", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(200, "成功", data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<T>(200, msg, data);
    }

    public static <T> Result<T> success(int code, String msg) {
        return new Result<T>(code, msg, null);
    }

    public static <T> Result<T> success(String msg) {
        return new Result<T>(200, msg, null);
    }

    /**
     *  消息发送失败
     * @return  返回响应消息
     */
    public static <T> Result<T> error() {
        return new Result<T>(500, "操作失败", null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<T>(500, msg, null);
    }

    public static <T> Result<T> error(int code,String msg) {
        return new Result<T>(code, msg, null);
    }

    public static <T> Result<T> error(int code,String msg, T data) {
        return new Result<T>(code, msg, data);
    }
}
